import io from 'socket.io-client'

class WS {
  constructor (event) {
    this.event = event
    const client = io('/main', { path: '/api/socket.io' })
    this.client = client
    client.on('connect', function () {
      console.log('Websocket Connected.')
    })
    client.on('connected', function (msg) {
      console.log('message: ', msg)
    })
    console.log('websocket client: ', this.client)
  }

  on (name, cb) {
    this.client.on(name, cb)
  }

  emit (name, data) {
    this.client.emit(name, data)
  }
}

function install (Vue) {
  var $event = Vue.prototype.$event
  Vue.prototype.$ws = new WS($event)
}

export default {
  install
}
